<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>parseZone() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>parseZone()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>parseZone()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/parsing/parse-zone/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/01-parsing/14-parse-zone.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment.parseZone()
moment.parseZone(String)
moment.parseZone(String, String)
moment.parseZone(String, [String])
moment.parseZone(String, String, Boolean)
moment.parseZone(String, String, String, Boolean)
</code></pre>

							</div>
<p>Moment &#x7684;&#x5B57;&#x7B26;&#x4E32;&#x89E3;&#x6790;&#x51FD;&#x6570;&#xFF08;&#x4F8B;&#x5982; <code>moment(string)</code> &#x548C; <code>moment.utc(string)</code>&#xFF09;&#x63A5;&#x53D7;&#x504F;&#x79FB;&#x91CF;&#x7684;&#x4FE1;&#x606F;&#xFF08;&#x5982;&#x679C;&#x63D0;&#x4F9B;&#xFF09;&#xFF0C;&#x4F46;&#x4F1A;&#x5C06;&#x751F;&#x6210;&#x7684; Moment &#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x4E3A;&#x672C;&#x5730;&#x6216; UTC &#x65F6;&#x95F4;&#x3002;
&#x76F8;&#x6BD4;&#x4E4B;&#x4E0B;&#xFF0C;<code>moment.parseZone()</code> &#x89E3;&#x6790;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4F46;&#x4F1A;&#x5C06;&#x751F;&#x6210;&#x7684; Moment &#x5BF9;&#x8C61;&#x4FDD;&#x6301;&#x5728;&#x56FA;&#x5B9A;&#x504F;&#x79FB;&#x91CF;&#x7684;&#x65F6;&#x533A;&#x4E2D;&#xFF08;&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x63D0;&#x4F9B;&#x7684;&#x504F;&#x79FB;&#x91CF;&#xFF09;&#x3002;</p>
<pre><code class="language-javascript">moment.parseZone(&quot;2013-01-01T00:00:00-13:00&quot;).utcOffset(); // -780 (&#x603B;&#x5206;&#x949F;&#x6570; &quot;-13:00&quot;)
moment.parseZone(&apos;2013 01 01 05 -13:00&apos;, &apos;YYYY MM DD HH ZZ&apos;).utcOffset(); // -780  (&#x603B;&#x5206;&#x949F;&#x6570; &quot;-13:00&quot;)
moment.parseZone(&apos;2013-01-01-13:00&apos;, [&apos;DD MM YYYY ZZ&apos;, &apos;YYYY MM DD ZZ&apos;]).utcOffset(); // -780  (&#x603B;&#x5206;&#x949F;&#x6570; &quot;-13:00&quot;);
</code></pre>
<p>&#x5B83;&#x8FD8;&#x5141;&#x8BB8;&#x4F20;&#x5165;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x548C;&#x4E25;&#x683C;&#x6027;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="language-javascript">moment.parseZone(&quot;2013 01 01 -13:00&quot;, &apos;YYYY MM DD ZZ&apos;, true).utcOffset(); // -780  (&#x603B;&#x5206;&#x949F;&#x6570; &quot;-13:00&quot;)
moment.parseZone(&quot;2013-01-01-13:00&quot;, &apos;YYYY MM DD ZZ&apos;, true).utcOffset(); // NaN (&#x672A;&#x901A;&#x8FC7;&#x4E25;&#x683C;&#x6027;&#x68C0;&#x67E5;)
moment.parseZone(&quot;2013 01 01 -13:00&quot;, &apos;YYYY MM DD ZZ&apos;, &apos;fr&apos;, true).utcOffset(); // -780 (&#x5E26;&#x6709;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x548C;&#x4E25;&#x683C;&#x6027;&#x53C2;&#x6570;)
moment.parseZone(&quot;2013 01 01 -13:00&quot;, [&apos;DD MM YYYY ZZ&apos;, &apos;YYYY MM DD ZZ&apos;], &apos;fr&apos;, true).utcOffset(); // -780 (&#x5E26;&#x6709;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x548C;&#x4E25;&#x683C;&#x6027;&#x53C2;&#x6570;&#x4EE5;&#x53CA;&#x683C;&#x5F0F;&#x7684;&#x6570;&#x7EC4;)
</code></pre>
<p><code>moment.parseZone</code> &#x7B49;&#x6548;&#x4E8E;&#x89E3;&#x6790;&#x5B57;&#x7B26;&#x4E32;&#x5E76;&#x4F7F;&#x7528; <code>moment#utcOffset</code> &#x89E3;&#x6790;&#x533A;&#x57DF;&#x3002;</p>
<pre><code class="language-javascript">var s = &quot;2013-01-01T00:00:00-13:00&quot;;
moment(s).utcOffset(s);
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment.parseZone()
moment.parseZone(String)
moment.parseZone(String, String)
moment.parseZone(String, [String])
moment.parseZone(String, String, Boolean)
moment.parseZone(String, String, String, Boolean)
</code></pre>

							</div>
<p>Moment&apos;s string parsing functions like <code>moment(string)</code> and <code>moment.utc(string)</code> accept offset information if provided, but convert the resulting Moment object to local or UTC time. In contrast, <code>moment.parseZone()</code> parses the string but keeps the resulting Moment object in a fixed-offset timezone with the provided offset in the string.</p>
<pre><code class="language-javascript">moment.parseZone(&quot;2013-01-01T00:00:00-13:00&quot;).utcOffset(); // -780 (&quot;-13:00&quot; in total minutes)
moment.parseZone(&apos;2013 01 01 05 -13:00&apos;, &apos;YYYY MM DD HH ZZ&apos;).utcOffset(); // -780  (&quot;-13:00&quot; in total minutes)
moment.parseZone(&apos;2013-01-01-13:00&apos;, [&apos;DD MM YYYY ZZ&apos;, &apos;YYYY MM DD ZZ&apos;]).utcOffset(); // -780  (&quot;-13:00&quot; in total minutes);
</code></pre>
<p>It also allows you to pass locale and strictness arguments.</p>
<pre><code class="language-javascript">moment.parseZone(&quot;2013 01 01 -13:00&quot;, &apos;YYYY MM DD ZZ&apos;, true).utcOffset(); // -780  (&quot;-13:00&quot; in total minutes)
moment.parseZone(&quot;2013-01-01-13:00&quot;, &apos;YYYY MM DD ZZ&apos;, true).utcOffset(); // NaN (doesn&apos;t pass the strictness check)
moment.parseZone(&quot;2013 01 01 -13:00&quot;, &apos;YYYY MM DD ZZ&apos;, &apos;fr&apos;, true).utcOffset(); // -780 (with locale and strictness argument)
moment.parseZone(&quot;2013 01 01 -13:00&quot;, [&apos;DD MM YYYY ZZ&apos;, &apos;YYYY MM DD ZZ&apos;], &apos;fr&apos;, true).utcOffset(); // -780 (with locale and strictness argument alongside an array of formats)
</code></pre>
<p><code>moment.parseZone</code> is equivalent to parsing the string and using <code>moment#utcOffset</code> to parse the zone.</p>
<pre><code class="language-javascript">var s = &quot;2013-01-01T00:00:00-13:00&quot;;
moment(s).utcOffset(s);
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>